using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWPZUAB
    {
        public DataRow Convert2WPZUAB(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWPZUAB(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WPAMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WPAPNRKR"] = " ".PadRight(2 ); 
         dwReturn["WPAPLFDNR"] = " ".PadRight(6 ); 
         dwReturn["WPAKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WPAWERK"] = " ".PadRight(3 ); 
         dwReturn["WPAABT"] = " ".PadRight(3 ); 
         dwReturn["WPAART"] = " ".PadRight(20 ); 
         dwReturn["WPAVAR"] = " ".PadRight(3 ); 
         dwReturn["WPADESS"] = " ".PadRight(10 ); 
         dwReturn["WPABESCHICH"] = " ".PadRight(10 ); 
         dwReturn["WPAZUSTAND"] = " ".PadRight(4 ); 
         dwReturn["WPAKZAM"] = " ".PadRight(1 ); 
         dwReturn["WPAANF"] = " ".PadRight(4 ); 
         dwReturn["WPAAENDZL"] = " ".PadRight(0 ); 
         dwReturn["WPAAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["WPAAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["WPANEUBEN"] = " ".PadRight(8 ); 
         dwReturn["WPANEUDAT"] = " ".PadRight(0 ); 
         dwReturn["WPAWERT"] = " ".PadRight(10 ); 
         dwReturn["WPAKZPA"] = " ".PadRight(1 ); 
         dwReturn["WPAKZBASIS"] = " ".PadRight(1 ); 
         dwReturn["WPAME"] = " ".PadRight(1 ); 
         dwReturn["WPAAUFTKZ"] = " ".PadRight(1 ); 
         dwReturn["WPAFILLER"] = " ".PadRight(84 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWPZUAB(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWPZUAB(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWPZUAB(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWPZUAB(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWPZUAB(dwLocal, ITXDBVERSION);
            }
            UpdateWPZUAB(dwLocal);
        }
        public void InsertWPZUAB(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WPZUAB(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWPZUAB(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WPZUAB WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WPZUAB  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WPZUAB";
            Return = Result;
            return Return;
        }
        public void DeleteWPZUAB(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WPZUAB   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWPZUAB(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WPZUAB SET "
                    +"WPAMANDANT= :WPAMANDANT,"
                    +"WPAPNRKR= :WPAPNRKR,"
                    +"WPAPLFDNR= :WPAPLFDNR,"
                    +"WPAKUNDNR= :WPAKUNDNR,"
                    +"WPAWERK= :WPAWERK,"
                    +"WPAABT= :WPAABT,"
                    +"WPAART= :WPAART,"
                    +"WPAVAR= :WPAVAR,"
                    +"WPADESS= :WPADESS,"
                    +"WPABESCHICH= :WPABESCHICH,"
                    +"WPAZUSTAND= :WPAZUSTAND,"
                    +"WPAKZAM= :WPAKZAM,"
                    +"WPAANF= :WPAANF,"
                    +"WPAAENDZL= :WPAAENDZL,"
                    +"WPAAENDBEN= :WPAAENDBEN,"
                    +"WPAAENDDAT= :WPAAENDDAT,"
                    +"WPANEUBEN= :WPANEUBEN,"
                    +"WPANEUDAT= :WPANEUDAT,"
                    +"WPAWERT= :WPAWERT,"
                    +"WPAKZPA= :WPAKZPA,"
                    +"WPAKZBASIS= :WPAKZBASIS,"
                    +"WPAME= :WPAME,"
                    +"WPAAUFTKZ= :WPAAUFTKZ,"
                    +"WPAFILLER= :WPAFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WPAMANDANT", OracleType.NVarChar).Value = dwData["WPAMANDANT"].ToString(); 
          or1.Parameters.Add("WPAPNRKR", OracleType.NVarChar).Value = dwData["WPAPNRKR"].ToString(); 
          or1.Parameters.Add("WPAPLFDNR", OracleType.NVarChar).Value = dwData["WPAPLFDNR"].ToString(); 
          or1.Parameters.Add("WPAKUNDNR", OracleType.NVarChar).Value = dwData["WPAKUNDNR"].ToString(); 
          or1.Parameters.Add("WPAWERK", OracleType.NVarChar).Value = dwData["WPAWERK"].ToString(); 
          or1.Parameters.Add("WPAABT", OracleType.NVarChar).Value = dwData["WPAABT"].ToString(); 
          or1.Parameters.Add("WPAART", OracleType.NVarChar).Value = dwData["WPAART"].ToString(); 
          or1.Parameters.Add("WPAVAR", OracleType.NVarChar).Value = dwData["WPAVAR"].ToString(); 
          or1.Parameters.Add("WPADESS", OracleType.NVarChar).Value = dwData["WPADESS"].ToString(); 
          or1.Parameters.Add("WPABESCHICH", OracleType.NVarChar).Value = dwData["WPABESCHICH"].ToString(); 
          or1.Parameters.Add("WPAZUSTAND", OracleType.NVarChar).Value = dwData["WPAZUSTAND"].ToString(); 
          or1.Parameters.Add("WPAKZAM", OracleType.NVarChar).Value = dwData["WPAKZAM"].ToString(); 
          or1.Parameters.Add("WPAANF", OracleType.NVarChar).Value = dwData["WPAANF"].ToString(); 
          or1.Parameters.Add("WPAAENDZL", OracleType.NVarChar).Value = dwData["WPAAENDZL"].ToString(); 
          or1.Parameters.Add("WPAAENDBEN", OracleType.NVarChar).Value = dwData["WPAAENDBEN"].ToString(); 
          or1.Parameters.Add("WPAAENDDAT", OracleType.NVarChar).Value = dwData["WPAAENDDAT"].ToString(); 
          or1.Parameters.Add("WPANEUBEN", OracleType.NVarChar).Value = dwData["WPANEUBEN"].ToString(); 
          or1.Parameters.Add("WPANEUDAT", OracleType.NVarChar).Value = dwData["WPANEUDAT"].ToString(); 
          or1.Parameters.Add("WPAWERT", OracleType.NVarChar).Value = dwData["WPAWERT"].ToString(); 
          or1.Parameters.Add("WPAKZPA", OracleType.NVarChar).Value = dwData["WPAKZPA"].ToString(); 
          or1.Parameters.Add("WPAKZBASIS", OracleType.NVarChar).Value = dwData["WPAKZBASIS"].ToString(); 
          or1.Parameters.Add("WPAME", OracleType.NVarChar).Value = dwData["WPAME"].ToString(); 
          or1.Parameters.Add("WPAAUFTKZ", OracleType.NVarChar).Value = dwData["WPAAUFTKZ"].ToString(); 
          or1.Parameters.Add("WPAFILLER", OracleType.NVarChar).Value = dwData["WPAFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
